﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace elfam.web.Models
{
    public class OrderLine: DomainEntity
    {
        public virtual Product Product { get; set; }
        public virtual string ProductName { get; set; }
        public virtual decimal Price { get; set; }
        public virtual int Quantity { get; set; }
        public virtual IList<Outcome> Outcomes { get; set; }
        public virtual Order Order { get; set; }

        public OrderLine()
        {
            Outcomes = new List<Outcome>();
        }

        public virtual void AddOutcome(Outcome outcome)
        {
            Outcomes.Add(outcome);
            outcome.OrderLine = this;
        }

        public virtual decimal Profit()
        {
            return Outcomes.Sum(outcome => outcome.Profit());
        }

        public virtual decimal SummWithDiscount()
        {
            return Outcomes.Sum(outcome => outcome.SummWithDiscount());
        }
    }
}